package com.shwread.android.qysw.activity.psychological;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckedTextView;
import android.widget.TextView;

import com.shwread.android.qysw.bean.psychological.QueInfo;
import com.shwread.android.qysw10000229.R;

import java.util.List;

public class EvaluatingOptionsListAdapter extends BaseAdapter {
    private UpListener listener;
    private boolean isFinish;
    private List<QueInfo.QueOptionBean> options;

    public EvaluatingOptionsListAdapter(List<QueInfo.QueOptionBean> options, boolean isFinish, UpListener listener) {
        this.options = options;
        this.isFinish = isFinish;
        this.listener = listener;
    }

    public int getCount() {
        return options.size();
    }

    @Override
    public boolean areAllItemsEnabled() {
        return false;
    }

    @Override
    public boolean isEnabled(int position) {
        return !isFinish;
    }

    @Override
    public boolean hasStableIds() {
        return true;
    }

    public Object getItem(int position) {
        return position;
    }

    public long getItemId(int position) {
        return position;
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            viewHolder = new ViewHolder();
            convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_que_option_list, parent, false);
            viewHolder.ctv = (CheckedTextView) convertView.findViewById(R.id.ctv_name);
            viewHolder.option = (TextView) convertView.findViewById(R.id.tv_option);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.option.setText(options.get(position).getOption_content());
        listener.updateBackground(position, viewHolder.ctv);
        return convertView;
    }

    private static class ViewHolder {
        CheckedTextView ctv;
        TextView option;
    }

    public interface UpListener {
        void updateBackground(int position, View view);
    }
}
